//查看图书详情
function viewBook(id){
	var url = "viewBookAction";
	var json_book = {
		id : id
	}; 

	if (id == "")
	{
		return;
	}else{
		$.post( url ,json_book , callback , "json" );
		function callback(json){
			var json_object =eval("("+json+")");
			var suc = json_object.suc;
			if(suc==0 ){
				document.getElementById("bookDetailContent").innerHTML="<div style='margin:20px;'>"
				+"<p>ISBN：<span style='font-weight:bold;'>"+json_object.msg+"</span></p>"
				+"</div>";
				$('#viewBookDetail').skygqbox({
					title:"错误",
					shut:"关闭",
					opacity:0.2
				});
			}else{
				document.getElementById("bookDetailContent").innerHTML="<div style='margin:20px;'>"
				+"<p>简介：<span style='font-weight:bold;'>"+json_object.synopsis+"</span></p>"
				+"<p>出版社：<span style='font-weight:bold;'>"+json_object.publish+"</span></p>"
				+"<p>作者：<span style='font-weight:bold;'>"+json_object.author+"</span></p>"
				+"<p>价格：<span style='font-weight:bold;'>"+json_object.price+"</span></p>"
				+"</div>";
				var title=json_object.name;
				$('#viewBookDetail').skygqbox({
					title:title,
					shut:"关闭",
					opacity:0.2
				});
			}
		}
	}
}

//打印书单
function printBookList(){
	
	var s = document.getElementsByName("chkBook");

	var html="";
	var i=0;
	var j=0;
	for( ; i < s.length; i++ )
	{
		if ( s[i].checked ){
			html+="<p>书名：<span style='font-weight:bold;'>"+s[i].value+"</span></p>"
			j++;
		}
	}
	if(j==0){
		document.getElementById("bookDetailContent").innerHTML="<div style='margin:20px;'>"
		+"<p><span style='font-weight:bold;'>请至少选择一本打印吧~~~</span></p>"
		+"</div>";
		$('#viewBookDetail').skygqbox({
			title:"错误",
			shut:"关闭",
			opacity:0.2
		});
	}else{
		document.getElementById("bookDetailContent").innerHTML="<div style='margin:20px;'>"
		+html
		+"<input type='button' onclick='beginPrint();' value='下一步'>"
		+"</div>";
		$('#viewBookDetail').skygqbox({
			title:"打印书单",
			shut:"关闭",
			opacity:0.2
		});
		
		
	}
	
//alert(s2);
	
}

function beginPrint(){
	
	document.getElementById("bookDetailContent").innerHTML="<div style='margin:20px;'>"
	+"<select class='select' name='printType'><option value='1'>黑白</option><option value='2'>彩色</option></select>"
	+"<p></p><input type='button' onclick='overPrint();' value='开始打印'>"
	+"</div>";

	$('#viewBookDetail').skygqbox({
		title:"打印类型",
		shut:"关闭",
		opacity:0.2
	});
}

function overPrint(){
	$.skygqbox.hide();
	alert("打印成功了,,,好开心啊~~~~");
}

function deleteBook(id){
	alert("ss");
	var url = "deleteBookAction";
	var json_book = {
		id : id
	}; 

	if (id == "")
	{
		return;
	}else{
		$.post( url ,json_book , callback , "json" );
		function callback(json){
			var json_object =eval("("+json+")");
			var suc = json_object.suc;
			if(suc==0 ){
				document.getElementById("bookDetailContent").innerHTML="<div style='margin:20px;'>"
				+"<p><span style='font-weight:bold;'>"+json_object.msg+"</span></p>"
				+"</div>";
				$('#viewBookDetail').skygqbox({
					title:"错误",
					shut:"关闭",
					opacity:0.2
				});
			}else{
				document.getElementById("bookDetailContent").innerHTML="<div style='margin:20px;'>"
				+"<p><span style='font-weight:bold;'>删除成功</span></p>"
				+"</div>";
				$('#viewBookDetail').skygqbox({
					title:"成功",
					shut:"关闭",
					opacity:0.2
				});
				window.location.href="adminViewBookListAction";
			}
		}
	}
}

function modifyBook(id){
	document.getElementById("bookDetailContent").innerHTML="<div style='margin:20px;'>"
	+"<p><span style='font-weight:bold;'>此功能还没实现</span></p>"
	+"</div>";
	$('#viewBookDetail').skygqbox({
		title:"没时间啦!!!!",
		shut:"关闭",
		opacity:0.2
	});
}

//借阅
function borrow(){
	var url = "borrowBookAction";
	var userId=$("#userId").val();
	var bookId=$("#bookId").val();
	if(userId==""){
		alert("用户ID不能为空");
	}else if(bookId==""){
		alert("图书ID不能为空");
	}else{
		var json_borrow = {
			userId : userId,
			bookId:bookId
		}; 
		$.post( url ,json_borrow , callback , "json" );
		function callback(json){
			alert(json);
		}
	}
}

//归还
function returnBook(){
	var url = "returnBookAction";
	var bookId=$("#bookId").val();
	if(bookId==""){
		alert("图书ID不能为空");
	}else{
		var json_return = {
			bookId:bookId
		}; 
		$.post( url ,json_return , callback , "json" );
		function callback(json){
			alert(json);
		}
	}
}

//预约
function reserve(){
	alert("还没实现哦亲!~~");
//	var url = "reserveBookAction";
//	var json_reserve = {
//		bookId:bookId,
//		userId:userId
//	}; 
//	$.post( url ,json_reserve , callback , "json" );
//	function callback(json){
//		alert(json);
//	}
	
}
